package com.project.shangqi.service.impl;

import com.project.shangqi.dto.LoginParam;
import com.project.shangqi.dto.LoginResult;
import com.project.shangqi.service.LoginService;
import com.project.shangqi.util.HttpUtil;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Override
    @Cacheable(value = "token", key = "#param.username")
    public LoginResult doLogin(LoginParam param, String url, Integer timeout) throws Exception {
        HttpUtil httpUtil = new HttpUtil(url, timeout);
        LoginResult result = httpUtil.doLogin(param);
        result.setCurrent(System.currentTimeMillis());
        return result;
    }

    @CacheEvict(value = "token", allEntries = true)
    public LoginResult clearToken() {
        return null;
    }
}
